//-----------------Sonic CD Door Script-------------------//
//------------------Scripted by makasinaaaa-------------------//
// Yeah...

// Aliases
#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.YVelocity
#alias Object.Value2	:	Object.T4
#alias Object.Value3	:	Object.TimerExtra
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod


#alias Object.PropertyValue		:	PushButton.Pressed	

 
// Priority
#alias 0	:	PRIORITY_BOUNDS
#alias 1	:	PRIORITY_ACTIVE

// States
#alias 0	:	FAN_ON
#alias 1	:	FAN_OFF

sub ObjectMain
	if PushButton[-2].Pressed == false
			Object.T4 = 0
	end if
	if Object.T4 == 0
		if PushButton[-2].Pressed == true
			if	Object.State == FAN_ON
				Object.State    = FAN_OFF
			end if
			if	Object.State == FAN_OFF
				Object.State    = FAN_ON
			end if
			Object.T4 = 1
		end if
	end if
end sub

sub ObjectPlayerInteraction
	switch Object.State
		case FAN_ON
			PlayerObjectCollision(C_TOUCH, -64, -256, 64, 0) //Detect
			if CheckResult == true
				Player.Gravity = 1
				Player.YVelocity += -25000
				//Player.YPos += Object.YVelocity
				if Player.YVelocity < -25000
					Player.YVelocity += -12500
				end if
				if Player.YVelocity > 10000
					Player.YVelocity -= 3000
				end if
			end if
			PlayerObjectCollision(C_TOUCH, -64, -384, 64, -128) //Detect
			if CheckResult == true
				Player.Gravity = 1
				if Player.YVelocity < -25000
					Player.YVelocity += 4500
				end if
				if Object.Timer == 8
					Object.Timer = 0
				end if
				if Player.YVelocity > 10000
					Player.YVelocity += 3000
				end if
			end if
			break
		case FAN_OFF
			PlayerObjectCollision(C_TOUCH, -64, -200, 64, 0) //Detect
			if CheckResult == true
			end if
			break
		end switch
end sub

sub ObjectDraw
	if Object.State == FAN_ON
		Object.Timer--
		if Object.Timer < 0
			Object.Timer = 2
			if Object.Frame > 3
				Object.Direction = 0
			else
				Object.Direction = 1
			end if
			if Object.Frame > 7
				Object.Frame = 0
			else
				Object.Frame++
			end if
		end if
	end if
		DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.Ypos)
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects3.gif")

		
	if HUD.CurrentTimePeriod > 1
		SpriteFrame(-47, -6, 94, 12, 69, 117)	// #0 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 130)	// #1 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 143)	// #2 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 156)	// #3 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 169)	// #4 Fan
		
		SpriteFrame(-47, -6, 94, 12, 69, 156)	// #3 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 143)	// #2 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 130)	// #1 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 117)	// #0 Fan
	else
		SpriteFrame(-47, -6, 94, 12, 69, 52)	// #0 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 65)	// #1 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 78)	// #2 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 91)	// #3 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 104)	// #4 Fan
		
		SpriteFrame(-47, -6, 94, 12, 69, 91)	// #3 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 78)	// #2 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 65)	// #1 Fan
		SpriteFrame(-47, -6, 94, 12, 69, 52)	// #0 Fan
	end if

end sub